package org.qqcui.designpattern.principles.dp;

import java.util.ArrayList;
import java.util.List;

/**
 * 迪米特法则示例二，修改成满足迪米特法则的情况
 *
 * @author cuiqingqiang
 * @version 1.0
 * @date 2020-10-14 21:57
 **/
public class Demter2 {
	public static void main(String[] args) {
		SchoolManager1 manager = new SchoolManager1();
		manager.printAllEmployeeInfo(new CollageManager1());
	}
}

/**
 * 学校总部员工类
 */
class Employee1 {
	private int id;

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}
}

/**
 * 学院员工类
 */
class CollageEmployee1 {
	private int id;

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}
}

/**
 * 学院员工管理类
 */
class CollageManager1 {

	public List<CollageEmployee1> getAllEmployee() {
		List<CollageEmployee1> collageEmployees = new ArrayList<CollageEmployee1>();
		for (int i = 0; i < 10; i++) {
			CollageEmployee1 collageEmployee = new CollageEmployee1();
			collageEmployee.setId(i);
			collageEmployees.add(collageEmployee);
		}
		return collageEmployees;
	}

	/**
	 * 新增满足迪米特法则的方法
	 */
	public void printCollageEmployee() {
		System.out.println("================学院员工信息====================");
		List<CollageEmployee1> list1 = getAllEmployee();
		for (CollageEmployee1 employee : list1) {
			System.out.println("学院员工id: " + employee.getId());
		}
	}
}

/**
 * 学校总部员工管理类
 */
class SchoolManager1 {

	public List<Employee1> getAllEmployee() {
		List<Employee1> employees = new ArrayList<Employee1>();
		for (int i = 0; i < 5; i++) {
			Employee1 employee = new Employee1();
			employee.setId(i);
			employees.add(employee);
		}
		return employees;
	}

	/**
	 * 修改此方法的实现，使其中的陌生类，放到其自己的管理类中去实现，此处只需要提供给一个public的方法就行了
	 * @param cm
	 */
	public void printAllEmployeeInfo(CollageManager1 cm) {
//		System.out.println("================学院员工信息====================");
//		List<CollageEmployee1> list1 = cm.getAllEmployee();
//		for (CollageEmployee1 employee : list1) {
//			System.out.println("学院员工id: " + employee.getId());
//		}

		cm.printCollageEmployee();

		System.out.println("=================学校总部员工信息======================");
		List<Employee1> list2 = this.getAllEmployee();
		for (Employee1 employee : list2) {
			System.out.println("学校总部员工id: " + employee.getId());
		}
	}
}